package com.sdry.system.controller;


import com.sdry.common.BaseController;
import com.sdry.common.ResultAppInfo;
import com.sdry.system.entity.SysAppMenu;
import com.sdry.system.service.AppMenuService;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * (SysAppMenu)表控制层
 *
 * @author makejava
 * @since 2020-04-07 13:53:28
 */
@RestController
@RequestMapping("sysAppMenu")
public class AppMenuController extends BaseController {

    /**
     * 服务对象
     */
    @Resource
    private AppMenuService AppMenuService;

    /**
     * 查询app接口--父接口
     * @param userId 用户ID
     * @return List<SysAppMenu>
     */
    @RequestMapping(value = "/api/queryAppMenuList")
    public ResultAppInfo queryAppMenuList(String userId) {
        List<SysAppMenu> sysAppMenuList = AppMenuService.queryAppMenuList(userId);
        return getResultAppInfo("1",sysAppMenuList,"");
    }

    /**
     * 查询app接口--子接口
     * @param amId 菜单ID
     * @return List<SysAppMenu>
     */
    @RequestMapping(value = "/api/queryAppMenuSonList")
    public ResultAppInfo queryAppMenuSonList(String amId,String userId) {
        List<SysAppMenu> sysAppMenuList = AppMenuService.queryAppMenuSonList(amId,userId);
        return getResultAppInfo("1",sysAppMenuList,"");
    }

    /**
     * 查询app接口web显示
     * @param roleId 角色ID
     * @return List<SysAppMenu>
     */
    @RequestMapping(value = "/queryAppMenuWenList")
    public String queryAppMenuWenList(Long roleId) {
        List<SysAppMenu> sysAppMenuList = AppMenuService.queryAppMenuWenList(roleId);
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.setExcludes(new String[] {
                "createDate","createBy", "delFlag",  "icon", "permissionType","seq", "updateBy","updateDate"
        });
        JSONArray jsonArray = JSONArray.fromObject(sysAppMenuList,jsonConfig);
        jsonArray.discard("amId").discard("pId").discard("name");
        return jsonArray.toString();
    }
}